#ifndef HTTPCONNECTOR_H
#define HTTPCONNECTOR_H

#include "connector.h"
#include "httprequest.h"
#include "misc.h"

namespace Wishmaster {

typedef std::deque<HttpRequestPtr> queueRequest;
typedef std::list<HttpRequestPtr> listRequest;

class WISHMASTER_EXPORT HttpConnector : public Connector
{
	Q_OBJECT
public:
	explicit HttpConnector(QObject *parent = 0);
	virtual ~HttpConnector();

	virtual void queue(const RequestPtr& request);
	virtual void queueFirst(const RequestPtr& request);

	virtual RequestPtr makeRequest(const QString& host, const QString& path,
								   const QString& method = "GET");

	virtual HttpRequestPtr makeHttpRequest(const QString& host, const QString& path,
										   const QString& method = "GET");

	virtual void connectRequest(QObject* eventReceiver, const char* resultSlot,
								const char* progressSlot, const RequestPtr& request);
	virtual RequestPtr request(int id);

	virtual void dequeue(int id);

	virtual void setCookieStorage(CookieStorage* storage);
	virtual CookieStorage* cookieStorage();

	QNetworkAccessManager* manager() { return m_networkManager; }

protected slots:
	void requestFinished(int id, bool error);

protected:
	virtual void startRequest(const HttpRequestPtr& request);
	virtual void clearDoneQueue();

private:
	QNetworkAccessManager* m_networkManager;
	int m_mainQueueLength;
	queueRequest m_pending;
	listRequest m_processing;
	listRequest m_done;
	CookieStorage* m_cookieStorage;
	friend class HttpRequest;
};

} // namespace Wishmaster

#endif // STANDARDCONNECTOR_H
